﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.Kinect.Nui;
using System.Reactive.Subjects;
using System.Windows.Media.Media3D;

namespace Kinect.KinectMouseControl
{
    public class RightHandPositionGesture : IEventPublisher<Point3D>
    {
        private IEventPublisher<SkeletonData> _skeletonDataPublisher;
        private Subject<Point3D> _rightHandPositionSubject;

        public RightHandPositionGesture(IEventPublisher<SkeletonData> skeletonDataPublisher)
        {
            _rightHandPositionSubject = new Subject<Point3D>();

            _skeletonDataPublisher = skeletonDataPublisher;
            _skeletonDataPublisher.EventObservable.Subscribe(x => ProcessSkeletonData(x));
        }

        private void ProcessSkeletonData(SkeletonData skeletonData)
        {
            var handRight = skeletonData.Joints[JointID.HandRight];

            _rightHandPositionSubject.OnNext(handRight.Position.ToPoint3D());
        }

        #region IEventPublisher<Point3D> Members

        public IObservable<Point3D> EventObservable
        {
            get { return _rightHandPositionSubject; }
        }

        #endregion
    }
}
